package com.amumu.drama.admin.modules.game.controller;

import com.amumu.drama.admin.modules.game.service.AdminPmsSkuStockService;
import com.amumu.drama.common.base.api.CommonPage;
import com.amumu.drama.common.base.api.CommonResult;
import com.amumu.drama.common.modules.category.dto.GameSkuBatchHandlerDto;
import com.amumu.drama.common.modules.category.dto.GameSkuQueryDto;
import com.amumu.drama.common.modules.category.dto.SkuStockDto;
import com.amumu.drama.common.modules.category.service.GameSkuService;
import com.amumu.drama.common.modules.category.vo.GameSkuVo;
import com.amumu.drama.common.modules.fulu.dto.ProductModifyDto;
import com.amumu.drama.common.modules.service.FuluCallbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 商品分类管理Controller
 * Created by macro on 2018/4/26.
 */
@RestController
@Api(tags = "微丸子-游戏sku管理")
@RequestMapping("/gameSku")
public class GameSkuController {
    @Autowired
    private GameSkuService gameSkuService;

    @Autowired
    private AdminPmsSkuStockService skuStockService;

    @Autowired
    private FuluCallbackService fuluCallbackService;

    @ApiOperation("新增游戏sku")
    @RequestMapping(value = "/addSkuStock", method = RequestMethod.POST)
    public CommonResult addSkuStock(@Validated @RequestBody SkuStockDto skuStockDto) {
        gameSkuService.addSkuStock(skuStockDto);
        return CommonResult.success();
    }

    @ApiOperation("编辑游戏sku")
    @RequestMapping(value = "/editSkuStock", method = RequestMethod.POST)
    public CommonResult editSkuStock(@Validated @RequestBody SkuStockDto skuStockDto) {
        return gameSkuService.editSkuStock(skuStockDto);
    }

    @ApiOperation("删除游戏sku")
    @RequestMapping(value = "/delete/{skuStockId}", method = RequestMethod.GET)
    public CommonResult deleteGame(@PathVariable Long skuStockId) {
        return gameSkuService.deleteSkuStock(skuStockId);
    }

    @ApiOperation("查询游戏商品列表")
    @RequestMapping(value = "/pageGameSkuList", method = RequestMethod.POST)
    public CommonResult<CommonPage<GameSkuVo>> pageGameList(@Validated @RequestBody GameSkuQueryDto gameQueryDto) {
        return CommonResult.success(gameSkuService.pageGameSkuList(gameQueryDto));
    }

    @ApiOperation("获取游戏sku详情")
    @RequestMapping(value = "/getGameSkuInfo/{skuStockId}", method = RequestMethod.GET)
    public CommonResult<GameSkuVo> getGameSkuInfo(@PathVariable Long skuStockId) {
        return gameSkuService.getGameSkuInfo(skuStockId);
    }

    @ApiOperation("批量同步库存信息")
    @RequestMapping(value = "/batchSynchronizeSkuStock", method = RequestMethod.GET)
    public CommonResult<String> batchSynchronizeSkuStock() {
        return gameSkuService.batchSynchronizeSkuStock();
    }

    @ApiOperation("sku批量上下架/绑定解绑游戏")
    @PostMapping(value = "/batchUpdate")
    public CommonResult batchUpdate(@RequestBody @Validated GameSkuBatchHandlerDto batchHandlerDto) {
        if (skuStockService.batchUpdateStatus(batchHandlerDto) <= 0) {
            return CommonResult.failed();
        }
        return CommonResult.success();
    }


    @ApiOperation("微丸子-商品信息变动回调")
    @RequestMapping(value = "/skuProductCallBack", method = RequestMethod.POST)
    @ResponseBody
    public String skuProductCallBack(@RequestBody ProductModifyDto productModifyDto) {
        int count = fuluCallbackService.skuProductCallBack(productModifyDto);
        if (count > 0) {
            return "sucess";
        } else {
            return "fail";
        }
    }
}
